package edenmedical;

import java.io.FileOutputStream;
import java.io.PrintStream;

public class Channel implements IChannel{

	public int send(ChannelMessage message) {
		DeviceType deviceType = DeviceType.valueOf(message.getParameters().get("measure[device]"));
		switch (deviceType)
		{
		case BILANCIA:
			try
			{		
			FileOutputStream os = null;
			os = new FileOutputStream("data/dbBilancia.txt",true);
			PrintStream out = new PrintStream(os);
			out.println(message.getParameters().get("measure[date_measure]")+";"+message.getParameters().get("measure[weight]"));
			}
			catch (Exception e)
			{
				e.printStackTrace();
			}
			FrmMain.getInstance().setLblStatoBilancia("Associato");
			FrmVisDatiPeso frmVisDatiPeso = new FrmVisDatiPeso("Bilancia",new String[]{message.getParameters().get("measure[date_measure]"),message.getParameters().get("measure[weight]")});
			frmVisDatiPeso.Show();
			break;
		case MIS_PRESSIONE:
			try
			{
			FileOutputStream os = null;
			os = new FileOutputStream("data/dbMisPressione.txt",true);
			PrintStream out = new PrintStream(os);
			out.println(message.getParameters().get("measure[date_measure]")+";"+
					message.getParameters().get("measure[massima]")+";"+
                    message.getParameters().get("measure[minima]")+";"+
                    message.getParameters().get("measure[meanArterialPressure]"));
			}
			catch (Exception e)
			{
				e.printStackTrace();
			}
			FrmMain.getInstance().setLblStatoPressione("Associato");
			FrmVisDatiPressione frmVisDatiPressione = new FrmVisDatiPressione("Misuratore Pressione",new String[]{message.getParameters().get("measure[date_measure]"),
					message.getParameters().get("measure[massima]"),
                    message.getParameters().get("measure[minima]"),
                    message.getParameters().get("measure[meanArterialPressure]")});
			frmVisDatiPressione.Show();
			break;
		case OMRON:
			try
			{
			FileOutputStream os = null;
			os = new FileOutputStream("data/dbOmron.txt",true);
			PrintStream out = new PrintStream(os);
			out.println(message.getParameters().get("measure[date_measure]")+";"+
					message.getParameters().get("measure[ossimetria]")+";"+
					message.getParameters().get("measure[pulsazioni]"));
			}
			catch (Exception e)
			{
				e.printStackTrace();
			}
			FrmMain.getInstance().setLblStatoOmron("Associato");
			FrmVisDatiPulsossimetro frmVisDatiPulsossimetro = new FrmVisDatiPulsossimetro("Pulsossimetro",new String[]{message.getParameters().get("measure[date_measure]"),
					 message.getParameters().get("measure[ossimetria]"),
					 message.getParameters().get("measure[pulsazioni]")},deviceType);
			frmVisDatiPulsossimetro.Show();
			break;
		case SAT300:
			try
			{
			FileOutputStream os = null;
			os = new FileOutputStream("data/dbSat300.txt",true);
			PrintStream out = new PrintStream(os);
			out.println(message.getParameters().get("measure[date_measure]")+";"+
					message.getParameters().get("measure[ossimetria]")+";"+
					message.getParameters().get("measure[pulsazioni]"));
			}
			catch (Exception e)
			{
				e.printStackTrace();
			}
			FrmMain.getInstance().setLblStatoSat300("Associato");
			FrmVisDatiPulsossimetro frmVisDatiPulsossimetro2 = new FrmVisDatiPulsossimetro("Pulsossimetro",new String[]{message.getParameters().get("measure[date_measure]"),
					 message.getParameters().get("measure[ossimetria]"),
					 message.getParameters().get("measure[pulsazioni]")},deviceType);
			frmVisDatiPulsossimetro2.Show();
			break;
		}
		return 1;
	}

}
